import http from '@/utils/request'

const apiBefore = '/web/api-service'
export const apiManager = {
  queryApiListApi: params => {
    return http.get(`${apiBefore}/data/api/list`, { params })
  },
  saveApiManegreApi: params => {
    return http.post(`${apiBefore}/data/api`, params)
  },
  updateApiManegreApi: params => {
    return http.put(`${apiBefore}/data/api/${params.id}/update`, params)
  },
  queryApiManegreInfoApi: params => {
    return http.get(`${apiBefore}/data/api/${params.id}/info`, { params })
  },
  deleteApiManegreApi: params => {
    return http.delete(`${apiBefore}/data/api/${params.id}/delete`)
  },
  getQACheckApiListApi: () => {
    return http.get(`${apiBefore}/data/api/tree`)
  },
  getLastSyncDate: (params) => {
    return http.get(`${apiBefore}/data/api/detail/getSyncDetailList/`, { params })
  },
  queryApiManegreListApi: (params) => {
    return http.get(`${apiBefore}/data/api/getDetailList`, { params })
  },
  getApiSubList: params => {
    return http.get(`${apiBefore}/data/api/listSub`, { params })
  },
  getCwStatusOptionList: params => {
    return http.get(`${apiBefore}/board-status/selectByList`, { params })
  },
  getCwOptionList: (type,params) => {
    return http.get(`${apiBefore}/cw/base/information?type=${type}`, { params })
  },
  getAssignedResourceOptionList: params => {
    return http.get(`${apiBefore}/users-identifiers/identifiers_users`, { params })
  },
  getQueueOptionList: params => {
    return http.get(`${apiBefore}/information/select`, { params })
  },
  getUsersOptionList: params => {
    if (params.type === 'autotask') {
      params.type = 'autotask'
    }
    return http.get(`${apiBefore}/users-identifiers/sysUser`, { params })
  },
  initRules: (tenantCode, task) => {
    if (!task) return http.get(`${apiBefore}/rest/next-ticket/${tenantCode}/initRules`)
    else return http.get(`${apiBefore}/rest/autotask/next-ticket/${tenantCode}/initRules`)
  },
  getTenantRuleListApi: (tenantCode, params) => {
    if (params.type === 'autotask') {
      params.type = 'autotask'
    }
    return http.get(`${apiBefore}/rest/rules/${tenantCode}`, { params })
  },
  postManuallySyncAPI: params => {
    return http.post(`${apiBefore}/sync/${params.tenantCode}/autoSync`, params)
  },
  getInfoApi: (params, config) => {
    return http.get(`${apiBefore}/data/api/detail/getSyncDetailList?action=${params.action}&subjectCode=${params.subjectCode}`, config)
  },
  getConnectorDetailInfo: params => {
    return http.post(`${apiBefore}/data/api/detail/getDetailList`, params)
  },
  getSyncResult: params => {
    return http.post(`${apiBefore}/sync/${params.tenantCode}/syncResult`, params)
  },
  getAutoTaskTicketScheduled: (params, tenantId) => {
    return http.get(`${apiBefore}/serviceCall/by-identifier/api?`, { params })
  },
  getCwTicketScheduled: (params) => {
    return http.get(`${apiBefore}/schedule/by-identifier/api`, { params })
  },
  getCwTicketScheduledbyTicketId: (params) => {
    return http.get(`${apiBefore}/schedule/by-ticket/api`, { params })
  },
  getBMSTicketScheduledbyTicketId: (params) => {
    return http.get(`${apiBefore}/schedule/kaseya/by-ticket/timelogs/api`, { params })
  },
  getJiraTicketScheduledbyTicketId: (params) => {
    return http.get(`${apiBefore}/jira/api/workLog?ticketId=${params.ticketId}`)
  },
  getAutoTaskTicketNotes: (params, tenantId, ticketId) => {
    if (params.type === 'autotask') {
      params.type = 'autotask'
    }
    return http.get(`${apiBefore}/rest/${params.type}/tickets/${tenantId}/notes/${ticketId}`, params)
  },
  getSyncStartApi: params => {
    return http.get(`${apiBefore}/dataset/sync/${params.tenantCode}/start`, { params })
  },
  getSyncResultApi: params => {
    return http.get(`${apiBefore}/dataset/sync/${params.tenantCode}/result`, { params })
  },
  deleteRejectReason: (params, tenantCode) => {
    if (params.type === 'autotask') {
      params.type = 'autotask'
    }
    return http.delete(`${apiBefore}/rest/reject/${tenantCode}`, { params })
  },
  // getWatchListSyncro: params => {
  //   return http.get(`${apiBefore}/companies/selectCompanies?type=syncro`, { params })
  // },
  // getWatchListkaseyabms: params => {
  //   return http.get(`${apiBefore}/companies/selectCompanies?type=kaseyabms`, { params })
  // },
  // getWatchListApi: params => {
  //   return http.get(`${apiBefore}/companies/selectCompanies?type=autotask`, { params })
  // },
  // getCompanyList: params => {
  //   return http.get(`${apiBefore}/companies/selectCompanies`, { params })
  // },
  getNewWatchListApi: (params, type) => {
    return http.get(`${apiBefore}/companies/selectCompanies?type=${type}`, { params })
  },
  getLocationSelectListApi: () => {
    return http.get(`${apiBefore}/location/select`)
  },
  getAutoContactApi: params => {
    return http.get(`${apiBefore}/contacts/select?type=autotask&limit=100`, { params })
  },
  getBoardNameListApi: params => {
    return http.get(`${apiBefore}/boards/ticket_board`)
  },
  getPrioritiesListApi: tenantCode => {
    return http.get(`${apiBefore}/priorities/list?tenantCode=${tenantCode}`)
  },
  getCwIdentifierUserApi: (params) => {
    return http.get(`${apiBefore}/users-identifiers/select`, { params })
  },
  storeHyperlinksApi: (params) => {
    return http.post(`${apiBefore}/nextTicket/click/log`, params)
  },
  updateDefaultRuleListApi: (params) => {
    return http.post(`${apiBefore}/rest/rules/template/batch`, params)
  },
  updateDefaultRuleApi: (params) => {
    return http.post(`${apiBefore}/rest/rules/template`, params)
  },
  savePageConfig: (params) => {
    return http.post(`${apiBefore}/page-config/update`, params)
  },
  getPageConfigList: (params) => {
    return http.get(`${apiBefore}/page-config/list`, params)
  },

  getSyncroStatusOption: params => {
    return http.get(`${apiBefore}/ticketSetting/getStatus`, { params })
  },
  editRuleName: params => {
    return http.put(`${apiBefore}/rest/model/save?type=${params.type}`, { ...params })
  },
}
